$(function() {
	//初始化
	Begin();
})

////////////--------------表格-数据--------------------////////////
var table = new VanyTable({
	el: "#table",
	url: "msgStatistic/getMsDraftById",
	index: true, //选框
	selection: true, //编号
	pages: true, //是否需要分页，与scrollPage最好二选一
	pageSize: 10,
	scrollPage: false, //是否滚动分页，与pages最好二选一
	//height: 200,  //固定高度，滚动分页时需要使用
	// right、topRight、bottomLeft
	btnPostion: "bottomLeft",//底部菜单所在位置
	btnNotes: "", //按钮旁边是否需要文字
	btns: [{
		authority: "base_user_add",
		name: "批量提醒",
		click: function() {
			console.log("批量提醒");
		}
	}],//底部菜单
	zidingyiBtn:'',  //底部菜单自定义
	zidingyiTop: '<el-form ref="form" :model="form" label-width="80px" class="btnright">' +
		'<el-row :gutter="20">' +
		'<el-col :span="18">' +
		'<el-form-item label="发送消息:"><el-time-picker is-range v-model="form.Timevalue" placeholder="选择时间范围"></el-time-picker></el-form-item>' +
		'<el-form-item label="关键词:"><el-input @change="_restore" @keyup.enter.native="search" :on-icon-click="search" v-model="form.searchValue" placeholder="请输入您要搜索的内容" icon="search"></el-input></el-form-item>' +
		'<el-button>搜索</el-button>' +
		'</el-col>' +
		'<el-col :span="6"  class="send"><el-button type="primary" onclick="sendMessage()">发消息</el-button></el-col>' +
		'</el-row>' +
		'</el-form>',  //头部按钮自定义，v-model中可以写form.value1到form.value8
	keys: [{
		"key": "title",
		"name": "标题消息"
	}, {
		"key": "process",
		"name": "发送进度",
		"template": "<el-progress v-if=\"scope.row.status === '发送失败'\" class='fail' :percentage='scope.row.progress'></el-progress>" +
			"<el-progress v-else :percentage='scope.row.progress'></el-progress>"
	}, {
		"key": "status",
		"name": "状态",
		"template": "<div v-if=\"scope.row.status === '发送失败'\"  style='color:#ff0000'><span v-text='scope.row.status'></span> <el-tooltip placement='bottom'><div slot='content' v-text='scope.row.statusDetail'></div><i class='el-icon-information'></i></el-tooltip></div><div v-else-if=\"scope.row.status === '正在发送'\"  style='color:#006ad3'><span v-text='scope.row.status'></span> </div><div v-else><span v-text='scope.row.status'></span> </div>"
	}, {
		"key": "setTime",
		"name": "创建时间"
	}, {
		"key": "operation",
		"name": "操作",
		"template": '<span @click="handleEdit(scope.$index, scope.row)">编辑</span> | <span @click="handleDel(scope.$index, scope.row)">删除</span>'
	}]//表格title
});

table.on("rowClick", function(index, row, event, column) {
	if(column.type === "selection" || column.property === "status") {
		return;
	}
	console.log("有一行被单击了");
});
table.on("selectionChange", function(selection) {
	console.log("有一行被选中啦");
});

table.getData({
	orgCode: "000000",
	searchValue: "",
	status: ""
}, true);

table.on("handleEdit", function(index, row) {
	var self = this;
	this.$confirm("确认编辑\n" + row.title + "？")
		.then(function() {
			done();
		})
		.catch(function() {});
	VanyAjax.prototype.hideLoading()
});

table.on("handleDel", function(index, row) {
	var self = this;
	this.$confirm("确认删除\n" + row.title + "？")
		.then(function() {
			done();
		})
		.catch(function() {});
	VanyAjax.prototype.hideLoading()
});
table.on("search", function(val) {
	table.getData({
		orgCode: "000000",
		searchValue: val,
		status: ""
	}, true);
});


//初始化
function Begin() {
	//面包屑
	new Vue().$mount('#crumbs');
	sessionStorage.Jurisdiction = "base_tag_addBaseRootTag,base_team_delTeamUsesr,base_user_update,base_tag_modifyBaseTag,base_team_modify,base_role_modifyRFAAndRemove,base_tagUser_export,base_customerUser_export,base_role_modifyRoleInfo,base_customer_import,base_org_delete,base_customer_addTag,base_team_delete,base_org_export,base_role_modifyRoleUser,base_user_resetUserStatus,base_org_import,base_user_export,base_tag_modifyTag,base_customer_add,base_customer_modifyTag,base_user_resetUserPassword,base_user_import,base_team_addTeamUsers,base_tag_deleteTag,base_user_deleteUsers,base_org_update,base_role_deleteRoleUser,base_user_moveUsers,base_teamUser_export,base_tag_addBaseTag,base_team_add,base_tag_selectTagUser,base_tag_addTag,base_customer_delCustomer,base_customer_addRootTag,base_tag_addRootTag,base_org_add,base_user_updateOrderNum,base_tag_deleteTagUser,base_tag_deleteBaseTag,base_customer_deleteTag,base_org_updateOrderNum,base_user_add"
}

//特殊td
function OnlyTd(obj) {
	$.ajax({
		url: "templates/authority/sendMessage/json/processList.json",
		method: "GET",
		success: function(newData) {
			//	 if(data.progressValue>=100){
			//    window.clearInterval(OnlyTd);
			//   }
			for(var i = 0; i < table.pageSize * table.currentPage; i++) {
				//				debugger
				$(".el-table__row").eq(i).find(".el-table_1_column_4 .el-progress-bar__inner").css("width", newData.resultData.rows[i].progress + "%")
				$(".el-table__row").eq(i).find(".el-table_1_column_4 .el-progress__text").html(newData.resultData.rows[i].progress + "%")
			}
		}
	})
}
//进度条及时更新
setInterval("OnlyTd()", 3000);

function sendMessage(){
	$("#content").load("templates/authority/sendMessage/sendMessage.html");
}
